package cn.bgs.utils;

import lombok.Data;

/**
 * 包名称： id.chen.springbootcrudtest.usermessage.utils
 * 类名称：CommonResult
 *
 * @author:陈峰 创建时间：2022/1/4/14:13
 */

/**
 * 返回结果工具类
 */
@Data
public class CommonResult {
    private int code=200;//状态码
    private boolean flag=true;//返回结果是否正确
    private Object obj; //结果集
    private Object o;

    public static CommonResult ok(){
        CommonResult commonResult = new CommonResult();
        return commonResult;
    }
    public static CommonResult ok(Object obj){
        CommonResult commonResult = new CommonResult();
        commonResult.setObj(obj);
        return commonResult;
    };
    public static CommonResult error(int code){

        return CommonResult.error(code,null);
    }
    public static CommonResult error(int code, Object obj){
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(code);
        commonResult.setFlag(false);
        commonResult.setObj(obj);
        return commonResult;
    }

    public static CommonResult ok(Object o, Object obj) {
        CommonResult commonResult = new CommonResult();
        commonResult.setObj(obj);
        commonResult.setObj(o);
//        commonResult.setObj(token);
        return commonResult;
    }
}
